﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using SubSonic;
using LinFen;
public partial class webUserControl_SupplierList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            GridView2.Visible = false;
            GridView1.Visible = true;
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if(e.CommandName == "DEL")
        {
            Literal1.Text = "";
            Query q = new Query("orderinfo");
            q.AddWhere("supplierID", e.CommandArgument.ToString());
            q.AddWhere("status", 0);
            if(q.GetRecordCount()>0)
            {
                //Literal1.Text = "<script language=javascript>alert('此数据已绑定，不可删除！');</script>";
                Response.Redirect("~/SupplierOrderList.aspx?sID=" + e.CommandArgument.ToString());
            }
            else
            {
                Literal1.Text = "<script language=javascript>alert('删除成功！');</script>";
                SupplierInfo.Delete("id", e.CommandArgument.ToString()); 
                GridView1.DataBind();
            }
            
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Literal1.Text = "";
        Response.Redirect("~/SupplierAdd.aspx");
    }
    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DEL")
        {
            Literal1.Text = "";
            Query q = new Query("orderinfo");
            q.AddWhere("supplierID", e.CommandArgument.ToString());
            q.AddWhere("status", 0);
            if (q.GetRecordCount() > 0)
            {
                //Literal1.Text = "<script language=javascript>alert('此数据已绑定，不可删除！');</script>";
                Response.Redirect("~/SupplierOrderList.aspx?sID=" + e.CommandArgument.ToString());
            }
            else
            {
                Literal1.Text = "<script language=javascript>alert('删除成功！');</script>";
                SupplierInfo.Delete("id", e.CommandArgument.ToString());
                GridView1.DataBind();
            }

        }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        if(TextBox1.Text =="")
        {
            GridView2.Visible = false;
            GridView1.Visible = true;
        }
        else
        {
            GridView2.Visible = true;
            GridView1.Visible = false;
        }
    }
}
